{{template "admin/header.html"}}
<title>新增页面模版 - GPRESS</title>
{{template "admin/bodystart.html"}}

{{ $maxSortNo:=  selectOne "pageTemplate" "max(sortNo) as sortNo from pageTemplate" }} 
<div class="layui-card layui-panel" style="height: 100%;">
	<div class="layui-card-header">
	  新增页面模版
	</div>
	<div class="layui-card-body">
	  <form class="layui-form" id="gpress-form" action="{{basePath}}admin/{{.UrlPathParam}}/save" method="POST">
		  <div class="layui-form-item layui-col-md6">
			<label class="layui-form-label">ID</label>
			<div class="layui-input-block">
			  <input type="hidden" name="status" id="status" value=1 />
			  <input type="text" name="id" lay-verify="required" lay-reqtext="请填写ID" autocomplete="off" class="layui-input" value="{{generateStringID}}" />
			</div>
		  </div>
		  <div class="layui-form-item layui-col-md6">
			  <label class="layui-form-label">模板名称</label>
			  <div class="layui-input-block">
				<input type="text" name="name" lay-verify="required" lay-reqtext="请填写模板名称" autocomplete="off" class="layui-input" value="">
			  </div>
		  </div>

		  <div class="layui-form-item layui-col-md6">
			<label class="layui-form-label">模板路径</label>
			<div class="layui-input-block">
			  <input type="text" name="templatePath" lay-verify="required" lay-reqtext="请填写模板路径" autocomplete="off" class="layui-input" value="">
			</div>
		  </div>
		  <div class="layui-form-item layui-col-md6">
			  <label class="layui-form-label">排序</label>
			  <div class="layui-input-block">
				<input type="number" name="sortNo" lay-verify="required" lay-reqtext="请填写排序" autocomplete="off" class="layui-input" value="{{addInt $maxSortNo.SortNo 1}}">
			  </div>
		  </div>				
		  <div class="layui-form-item">
			  <div class="layui-input-block">
				<button type="submit" class="layui-btn layui-bg-blue" lay-submit lay-filter="gpress-form-ajax-update">提交保存</button>
			  </div>
		  </div>
	  </form>
	</div>
  </div>
{{template "admin/bodyend.html"}}

<script>
layui.use(function(){
var form = layui.form;
var layer = layui.layer;
var $ =layui.jquery;
// 提交事件
form.on('submit(gpress-form-ajax-update)', function(data){
  var field = data.field; // 获取表单字段值
  field.sortNo=field.sortNo-0;
  field.status=field.status-0;
  const form = document.getElementById('gpress-form');
  $.ajax({
	  url:form.action,
	  type:form.method,
	  contentType: "application/json;charset=utf-8",
	  dataType:"json",
	  data:JSON.stringify(field),
	  error:function(){
		  layer.msg("保存错误,请重试!");
	  },
	  success:function(result){
		  if (result.statusCode == 1) {
			layer.confirm('保存成功,是否继续添加?', {
			icon: 3,
			title:"确认",
			btn: ['返回列表','继续添加' ] //按钮
			}, function () {
				window.location.href = '{{basePath}}admin/{{.UrlPathParam}}/list';
			},function () {
				location.reload();
			});
		  }else{
			  layer.msg("保存失败!");
		  }
	  }
  });
  return false; // 阻止默认 form 跳转
});
});
</script>
